package com.zhentao.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.mapper.CdzExceptionalRetroactionMapper;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.model.common.pojo.coupon.CdzExceptionalRetroaction;
import com.zhentao.service.ICdzExceptionalRetroactionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author mp
 * @since 2024-12-18
 */
@Service
public class CdzExceptionalRetroactionServiceImpl extends ServiceImpl<CdzExceptionalRetroactionMapper, CdzExceptionalRetroaction> implements ICdzExceptionalRetroactionService {
@Autowired
private CdzExceptionalRetroactionMapper cdzExceptionalRetroactionMapper;
    @Override
    public ResponseResult selectAll() {
        List<CdzExceptionalRetroaction> cdzExceptionalRetroactions = cdzExceptionalRetroactionMapper.selectAll();
        return ResponseResult.okResult(cdzExceptionalRetroactions);
    }

    @Override
    public ResponseResult updateex(CdzExceptionalRetroaction cdzExceptionalRetroaction) {
        int i = cdzExceptionalRetroactionMapper.updateById(cdzExceptionalRetroaction);
        if (i > 0) {
            // 更新成功后，去自动更新状态2
            //实体类对象
            CdzExceptionalRetroaction updateStatusObj = new CdzExceptionalRetroaction();
            updateStatusObj.setId(cdzExceptionalRetroaction.getId());
            updateStatusObj.setStatus(2);
            int updateStatusResult = cdzExceptionalRetroactionMapper.updateById(updateStatusObj);
            if (updateStatusResult > 0) {
                return ResponseResult.okResult(i);
            } else {
                // 这里可以根据实际情况处理状态更新失败的逻辑，比如抛异常或者返回特定的错误响应等
                return ResponseResult.errorResult(i);
            }
        }
        return ResponseResult.okResult(i);
    }



}
